package com.example.cofeed.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.blankj.utilcode.util.ActivityUtils;
import com.example.cofeed.R;
import com.example.cofeed.adapter.MessageNotificationAdapter;
import com.example.cofeed.api.ApiService;
import com.example.cofeed.base.BaseActivity;
import com.example.cofeed.base.BaseListActivity;
import com.example.cofeed.callback.DialogCallback;
import com.example.cofeed.callback.LzyResponse;
import com.example.cofeed.constant.IntentKeyConstant;
import com.example.cofeed.entity.MessageNotification;
import com.lzy.okgo.model.Response;
import com.umeng.analytics.MobclickAgent;

import java.util.List;

public class MessageNotificationActivity extends BaseListActivity<MessageNotification> {

    private MessageNotificationAdapter mMessageNotificationAdapter;

    @Override
    protected void bindRecyclerView(RecyclerView recLv) {
        setMainTitle("消息");

        recLv.setLayoutManager(new LinearLayoutManager(this));
        recLv.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL));
        mMessageNotificationAdapter = new MessageNotificationAdapter();
        recLv.setAdapter(mMessageNotificationAdapter);
        mMessageNotificationAdapter.setOnItemClickListener((adapter, view, position) -> {
            MessageNotification messageNotification = (MessageNotification) adapter.getData().get(position);
            Intent intent = null;
            switch (messageNotification.type){
                case "1":
                    ActivityUtils.startActivity(SystemMessagesActivity.class);
                    break;
                case "2":
                    intent = new Intent(this, ReplyCommentsActivity.class);
                    intent.putExtra(IntentKeyConstant.TYPE, 1);
                    startActivity(intent);
                    break;
                case "3":
                    ActivityUtils.startActivity(ReplyCommentsActivity.class);
                    break;
                case "4":
                    intent = new Intent(this, ReplyCommentsActivity.class);
                    intent.putExtra(IntentKeyConstant.TYPE, 2);
                    startActivity(intent);
                    break;
                    default:
            }
        });
    }

    @Override
    protected void loadData(int page, int pageCount) {

        ApiService.menu_message(this, new DialogCallback<LzyResponse<List<MessageNotification>>>() {
            @Override
            public void onSuccess(Response<LzyResponse<List<MessageNotification>>> response) {
                onGetDataSuc(response.body().data);
            }
        });

    }

    @Override
    protected List<MessageNotification> getData() {
        return mMessageNotificationAdapter.getData();
    }

    @Override
    protected void bindData(boolean isRefresh, List<MessageNotification> list) {
        if (isRefresh){
            mMessageNotificationAdapter.setNewData(list);
        }else {
            mMessageNotificationAdapter.addData(list);
        }

    }

    @Override
    public void onResume() {
        super.onResume();
        MobclickAgent.onResume(this);
    }

    @Override
    public void onPause() {
        super.onPause();
        MobclickAgent.onPause(this);
    }
}
